package Support;
import java.awt.Component;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
public class FormattedCellRenderer extends DefaultTableCellRenderer {

    protected SimpleDateFormat format;

    public FormattedCellRenderer(SimpleDateFormat format) {
        this.format = format;
    }
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
            int nRow, int nCol) {
    	Component cmp = null; 
    	try
    	{
    		//Wed Sep 11 00:00:00 ICT 2013
    		 Date date;
	    	 if(!value.toString().contains("-"))
	    	 {
	    		 date = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy").parse(value.toString());
	    	 }
	    	 else { 
	    		 date = new SimpleDateFormat("dd-MM-yyyy").parse(value.toString());
	    	 }
	    	 cmp = super.getTableCellRendererComponent(table, (value == null) ? null : format.format(date), isSelected, hasFocus, nRow, nCol);
	    	 if(cmp != null)
	    		 table.setValueAt(true, nRow, nCol-1);
    	} catch(Exception ex) {
    		//System.out.println(ex.toString());
    	}
    	return cmp;
    }
}